#include "qmidimark.h"
#include "qmidinote.h"
#include <QMenuBar>
#include <QMenu>
#include <QFileDialog>
#include <QTabWidget>
#include <QApplication>
#include <QVBoxLayout>
#include <qglobal.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

	QWidget frame;
	auto size = QSize(800, 400);
	frame.resize(size);

	auto menuBar = new QMenuBar;
	auto menu = new QMenu(QObject::tr("File"));
	auto openAction = new QAction(QObject::tr("Open"));
	auto exitAction = new QAction(QObject::tr("Close"));

	menu->addAction(openAction);
	menu->addAction(exitAction);
	menuBar->addMenu(menu);
	frame.setContextMenuPolicy(Qt::ActionsContextMenu);

	QMidiNote note;
	QMidiMark mark;

	auto w = new QTabWidget;
	w->addTab(&note, "Note");
	w->addTab(&mark, "Mark");

	QObject::connect(openAction, QOverload<bool>::of(&QAction::triggered),
		[&](bool check) {
		auto fileName = QFileDialog::getOpenFileName(&frame,
			QObject::tr("Open Midi"), "", QObject::tr("Midi Files (*.mid)"));

		if (!fileName.isEmpty())
		{
			note.open(fileName);
			mark.open(fileName);
		}
	});
	QObject::connect(exitAction, &QAction::triggered, &frame, &QWidget::close);

	auto layout = new QVBoxLayout;
	layout->addWidget(menuBar);
	layout->addWidget(w);
	frame.setLayout(layout);
	frame.show();

    return a.exec();
}
